package com.moleq.models;

import com.moleq.db.DatabaseSchema;
import com.moleq.logic.MoleQConstants;
import com.moleq.mgpos.activities.R;

public class FunctionPanel {
	public static final int GLOBAL_DISCOUNT_MANUAL_PERCENT 		= 0;
	public static final int GLOBAL_DISCOUNT_REMOVE 				= -1;
	public static final int ITEM_DISCOUNT_MANUAL_PERCENT 		= 0;
	public static final int ITEM_DISCOUNT_MANUAL_AMOUNT 		= -1;
	public static final int WIC_NEW_EDIT 						= 0;
	public static final int WIC_REMOVE 							= -1;
	public static final int CVV_NEW_EDIT 						= 0;
	public static final int CVV_REMOVE 							= -1;
	public static final String COUPON_PERCENT				 	= "P";
	public static final String COUPON_AMOUNT 					= "A";
	public static final String COUPON_MANUAL_PERCENT 			= "M";
	public static final String COUPON_MANUAL_AMOUNT 			= "N";
	public static final String MANUAL_TARE						= "M";
	public static final String UNIT_OF_TARE						= "U";
			
	// CREATE TABLE IF NOT EXISTS t_function_panel
	// (tp_no INTEGER NOT NULL,
	// tp_order integer NOT NULL,
	// tp_func_key integer NOT NULL,
	// tp_label_file varchar(50) NOT NULL,
	// tp_appl_fl varchar(1) DEFAULT '0' NULL,
	// tp_parameter1 varchar(10) NULL,
	// tp_parameter2 integer NULL,
	// create_datetime varchar(14) NOT NULL,
	// update_datetime varchar(14) NOT NULL,
	// PRIMARY KEY (tp_no));
	private int tp_no;
	private int tp_order;
	private int tp_func_key;
	private String tp_label_file;
	private String tp_appl_fl;
	private String tp_parameter1;
	private int tp_parameter2;
	private String create_datetime;
	private String update_datetime;
	private double tp_parameter3;
	private String tp_label_file2;
	public String isAppl = "";
	
	public FunctionPanel() {}
	public FunctionPanel(int tp_no, int tp_order, int tp_func_key,
			String tp_label_file, String tp_appl_fl, String tp_parameter1,
			int tp_parameter2, String create_datetime, String update_datetime,
			double tp_parameter3, String tp_label_file2) {
		this.tp_no = tp_no;
		this.tp_order = tp_order;
		this.tp_func_key = tp_func_key;
		this.tp_label_file = tp_label_file;
		this.tp_appl_fl = tp_appl_fl;
		this.tp_parameter1 = tp_parameter1;
		this.tp_parameter2 = tp_parameter2;
		this.create_datetime = create_datetime;
		this.update_datetime = update_datetime;
		this.tp_parameter3 = tp_parameter3;
		this.tp_label_file2 = tp_label_file2;
	}

	public int getTp_no() {
		return tp_no;
	}

	public void setTp_no(int tp_no) {
		this.tp_no = tp_no;
	}

	public int getTp_order() {
		return tp_order;
	}

	public void setTp_order(int tp_order) {
		this.tp_order = tp_order;
	}

	public int getTp_func_key() {
		return tp_func_key;
	}

	public void setTp_func_key(int tp_func_key) {
		this.tp_func_key = tp_func_key;
	}

	public String getTp_label_file() {
		return tp_label_file;
	}

	public void setTp_label_file(String tp_label_file) {
		this.tp_label_file = tp_label_file;
	}

	public String getTp_appl_fl() {
		return tp_appl_fl;
	}
	
	public void setTp_appl_fl(String tp_appl_fl) {
		
		this.tp_appl_fl = tp_appl_fl;
	}
	public String getTp_parameter1() {
		return tp_parameter1;
	}

	public void setTp_parameter1(String tp_parameter1) {
		this.tp_parameter1 = tp_parameter1;
	}

	public int getTp_parameter2() {
		return tp_parameter2;
	}

	public void setTp_parameter2(int tp_parameter2) {
		this.tp_parameter2 = tp_parameter2;
	}
	
	public double getTp_parameter3() {
		return tp_parameter3;
	}

	public void setTp_parameter3(double tp_parameter3) {
		this.tp_parameter3 = tp_parameter3;
	}

	public String getTp_label_file2() {
		return tp_label_file2;
	}

	public void setTp_label_file2(String tp_label_file2) {
		this.tp_label_file2 = tp_label_file2;
	}
	
	public String getCreate_datetime() {
		return create_datetime;
	}
	public void setCreate_datetime(String create_datetime) {
		this.create_datetime = create_datetime;
	}
	public String getUpdate_datetime() {
		return update_datetime;
	}
	public void setUpdate_datetime(String update_datetime) {
		this.update_datetime = update_datetime;
	}
	
	public String getDisplayText() {
		String result = "";
		if (tp_label_file != null && tp_label_file.length() > 0) {
			result = tp_label_file;
		}

		if (tp_label_file2 != null && tp_label_file2.length() > 0) {

			if (result.length() > 0) {

				result += "\n" + tp_label_file2;
			} else {

				result += tp_label_file2;
			}
		}

		return result;
	}

	public int getIconId() {
		int result = -1;

		switch (tp_func_key) {
		case MoleQConstants.FUNCTION_CASH:
			result = R.drawable.cash;
			break;
		case MoleQConstants.FUNCTION_CREDITCARD:
			result = R.drawable.crdcard;
			break;
		case MoleQConstants.FUNCTION_DEBITCARD:
			result = R.drawable.dbtcard;
			break;
		case MoleQConstants.FUNCTION_FOODSTAMP:
			result = R.drawable.food;
			break;
		case MoleQConstants.FUNCTION_CHECK:
			result = R.drawable.checks;
			break;
		case MoleQConstants.FUNCTION_GIFTCARD:
			result = R.drawable.giftcard;
			break;
		case MoleQConstants.FUNCTION_ERROR_CORRECT:
			result = R.drawable.eraser48;
			break;
		case MoleQConstants.FUNCTION_VOID:
			result = R.drawable.cancel1;
			break;
		case MoleQConstants.FUNCTION_TARE:
			result = R.drawable.tare;
			break;
		case MoleQConstants.FUNCTION_PRICE_CHANGE:
			result = R.drawable.tare;
			break;
		case MoleQConstants.FUNCTION_GLOBAL_DISCOUNT:
			result = R.drawable.discount;
			break;
		case MoleQConstants.FUNCTION_COUPON:
			result = R.drawable.coupon;
			break;
		case MoleQConstants.FUNCTION_TAX_EXEMPT:
			result = R.drawable.nomoney;
			break;
		case MoleQConstants.FUNCTION_CANCEL:
			result = R.drawable.cancel;
			break;
		case MoleQConstants.FUNCTION_REFUND:
			result = R.drawable.return48;
			break;
		case MoleQConstants.FUNCTION_NO_SALE:
			result = R.drawable.no_sale;
			break;
		case MoleQConstants.FUNCTION_CUSTOMER:
			result = R.drawable.menber;
			break;
		case MoleQConstants.FUNCTION_ITEM_DISOCUNT:
			result = R.drawable.item_discount;
			break;
		case MoleQConstants.FUNCTION_SHIFT_TAX:
			result = R.drawable.shift;
			break;
		case MoleQConstants.FUNCTION_SHIFT_FOODSTAMP:
			result = R.drawable.shift;
			break;
		case MoleQConstants.FUNCTION_CVV:
			result = R.drawable.food;
			break;
		case MoleQConstants.FUNCTION_WIC:
			result = R.drawable.wic;
			break;
		case MoleQConstants.FUNCTION_SIGN_OUT:
			result = R.drawable.exit;
			break;
		default:
			result = R.drawable.item_discount;
			break;
		}

		// result = R.drawable.item_discount;
		return result;
	}
	
	public String toMGData(String Action){
		String Result = Action + "|" + DatabaseSchema.FunctionPanel.SCHEMA_NAME 
					+ "|(" + getTp_no() + "," + getTp_order() + "," + getTp_func_key() 
					+ "," + CheckNull(getTp_label_file()) +"," + CheckNull(getTp_appl_fl()) + "," + CheckNull(getTp_parameter1())
					+ "," + getTp_parameter2() + "," + CheckNull(getCreate_datetime()) + "," + CheckNull(getUpdate_datetime())
					+ "," + getTp_parameter3() + "," + CheckNull(getTp_label_file2()) + ")";
		return Result;
	}
	
	public String CheckNull(String value){
		if(value == null){
			return null;
		}else{
			return "'" + value + "'";
		}
	}
}
